/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sv.com.intesal.compra.sql;

/**
 *
 * @author ejerez
 */
public class SQLAbonoCompra {

    public static final String insertAbonoCompra="INSERT INTO ABONO_COMPRA(id_c,id_u,fecha_ac,fechahora,monto_ac,estado_ac,numero_documento_ac)VALUES(?,?,?,now(),?,?,?)";
    public static final String updateAbonoCompra="UPDATE ABONO_COMPRA SET id_c=?, fecha_ac=?,monto_ac=?,estado_ac=?,numero_documento_ac=? where id_ac=?";
    public static final String deleteAbonoCompra="DELETE FROM ABONO_COMPRA where id_ac=?";

    public static final String setEstado="UPDATE ABONO_COMPRA SET estado_ac=? where id_ac=?";
    public static final String getMax="SELECT max(id_ac) as max FROM ABONO_COMPRA";

    public static final String getAbonos_x_Compra="SELECT ac.*,u.usuario_u from ABONO_COMPRA as ac,USUARIO as u,ENCA_COMPRA as c where c.id_c=ac.id_c and u.id_u=ac.id_u and ac.id_c=?";
    public static final String getSumaAbonos_x_Compra="select COALESCE(sum(ac.monto_ac),0.0) Total_Abono FROM ABONO_COMPRA as ac,ENCA_COMPRA as c where c.id_c=ac.id_c and ac.estado_ac='AC' and c.id_c=?";

    /*Trae Total de Compra y Total de Abono por Compra*/
    public static final String getSumaTotal_Compra_y_AbonoCompra="select sum((d.cantidad_d*d.costo_d)+d.iva_d+d.exento_d) Total_Compra,(select COALESCE(sum(ac.monto_ac),0.0) FROM ABONO_COMPRA as ac,ENCA_COMPRA as c where c.id_c=ac.id_c and ac.estado_ac='AC' and c.id_c=?) Total_Abono from enca_compra as c,deta_compra as d where c.id_c=d.id_c and c.id_c=?";



}